package com.example.kotlindemo.ui

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.example.kotlindemo.R
import com.example.kotlindemo.constructorstudy.Food
import com.example.kotlindemo.constructorstudy.Fruits2
import com.example.kotlindemo.coroutine.CoroutineSample
import com.example.kotlindemo.genericity.Consumer
import com.example.kotlindemo.genericity.ConsumerOut
import com.example.kotlindemo.genericity.Producer
import com.example.kotlindemo.utils.LogUtil

class SecondActivity : BaseActivity() {


    lateinit var tvTest: TextView

    var coroutineSample :CoroutineSample ?= null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.e("long", "SecondActivity onCreate 执行")
        Log.e("long", "打印父类的str参数" + str)
        coroutineSample = CoroutineSample()
        tvTest = findViewById(R.id.tv_test)
        tvTest.setOnClickListener(object : View.OnClickListener {
            override fun onClick(p0: View?) {
//                abc()
                operator()
                coroutineSample!!.threadTest()
            }
        })



        //等价于
//        tvTest.setOnClickListener(View.OnClickListener { abc() })


    }

    override fun abc() {
        super.abc()
        Log.e("long", "调用父类的 abc函数")
    }


    /**
     *  泛型
     *      每次声明的时候都要添加泛型，很麻烦，其实可以放在Consumer中
     */
    fun genericitySample() {
        val consumer: Consumer<in Button> =
            Consumer<TextView>()
        consumer.consume(Button(this))

        //简写方式
        val producer: Producer<out TextView> = Producer<Button>()
        val textView: TextView ?= producer.produce()
    }


    var d = 0
    var e = 0
    fun operator(){
        var a : Int = 0
        var b = ++a
        var c = a.inc()
        val inc = d.inc()
        e.inc().also{ e = it }
        Log.e("===","(.java:68)$e")
    }
}